﻿using System.ComponentModel;

namespace Tms.Model
{
    public class PagingPara
    {
        //页大小（每页多少行）
        public int PageSize { get; set; } = 16;

        //页索引（第几页）
        public int PageIndex { get; set; } = 1;

        //总页数
        public int TotalPages
        {
            get
            {
                int rtn = 0;
                if (PageSize == 0) return rtn;
                rtn = (TotalRecords + PageSize - 1) / PageSize;
                return rtn;
            }
        }

        //当前页记录数（等于PageSize，最后一页可能例外）
        public int Records { get; set; } = 0;

        //总记录数
        public int TotalRecords { get; set; } = 0;

        //是否显示记录数
        public bool IsShowRecords { get; set; } = true;

        //排序
        public string SortColumn { get; set; } = null;
        public ListSortDirection? SortDirection { get; set; } = null;
        public string Orderby
        {
            get
            {
                string rtn = "";
                if (string.IsNullOrEmpty(SortColumn)) return rtn;

                string strDrt = "";
                if (SortDirection == null) strDrt = "asc";                
                else if (SortDirection == ListSortDirection.Ascending) strDrt = "asc";                
                else if (SortDirection == ListSortDirection.Descending) strDrt = "desc";
                
                rtn = SortColumn + " " + strDrt;

                //解决非唯一字段排序问题
                if (!string.IsNullOrEmpty(ExtSortColumn) && SortColumn != ExtSortColumn)  //目前只能扩展一个排序字段
                {
                    //rtn = rtn + " ," + ExtSortColumn + " " + strDrt;   //扩展排序字段与主排序字段同向
                    rtn = rtn + " ," + ExtSortColumn + " asc";           //扩展排序字段方向固定为正序
                }

                return rtn;
            }
        }
        
        //解决非唯一字段排序问题
        public string ExtSortColumn { get; set; } = null;

    }
}
